<?php 

/////////     NEXT: ADD IN THE REST OF THE INFO NEEDED FOR IMPORT AND MAKE FM SCRIPT TO SUCK IT IN
/////////     USING THE FOLLOWING IN GET SYNTAX:
/////////     ?last=[last id imported]&key=199ex17255e41167816dr5t3e


 $link = mysql_connect('localhost', 'kootenay', 'nonsense');

 if (!$link) {
  die ('Not connected : ' . mysql_error());
 }

 $db_selected = mysql_select_db('kootenay', $link);

 if (!$db_selected) {
  die ('Can\'t use foo : ' . mysql_error());
 }



$getID = $_GET['id'];
$key = $_GET['key'];


if ($key == "199ex17255e41167816dr5t3e") { 

   if ($lastID == "") { $lastID = 0;}

echo <<<eof
<?xml version="1.0" encoding="UTF-8" ?><FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"><ERRORCODE>0</ERRORCODE><PRODUCT BUILD="06-20-2006" NAME="FileMaker Pro" VERSION="8.5v1"/><DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="Ginkgo" RECORDS="715" TIMEFORMAT="h:mm:ss a"/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="artist_name" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="album_name" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="category_id" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="review" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="reviewer" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="cancon" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="date_added" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="label" TYPE="TEXT"/>





</METADATA>
<RESULTSET FOUND="1">

eof;

$categories[1] = "1  N Audio Art";
$categories[2] = "2  J  Classical / Opera";
$categories[3] = "3  F  Cultural / International / World Beat";
$categories[4] = "4  H  Dance / House";
$categories[5] = "5  I   Electronica / Ambient / Avant Garde";
$categories[6] = "6  E  Folk / Singer Songwriter";
$categories[7] = "7  O  Gospel";
$categories[8] = "8  G  Hip Hop / Rap";
$categories[9] = "9  A   Jazz / Blues";
$categories[10] = "10 C  New Age / Instrumental";
$categories[11] = "11  D  Old Time / Country / Bluegrass";
$categories[12] = "12  B  Pop / Rock";
$categories[13] = "13  M  Punk / Metal / Ska";
$categories[14] = "14  P  Seasonal/  Christmas";
$categories[15] = "15  K  Soundtrack/Compilation";
$categories[16] = "16  L  Spoken Word";
$categories[17] = "17  Q  Funk / Acid Jazz";
$categories[18] = "18  R  Children";


$result = mysql_query('SELECT * FROM ml_albums WHERE album_id = "' . $getID . '"');


while ($row = mysql_fetch_array ($result)) {

//$count = count ($row); echo "count: " . $count;

$id = $row[0];

$artist = ucwords($row['artist']);
$title = ucwords($row['title']);
$category = $row['section_id']; $category_id = $categories[$category];
$review = $row['freetext'];
$reviewer = $row['creation_user'];
if ($row['cancon_p'] == "Y") {$cancon = 1;}else{$cancon = 0;};
$date_added= dateformat($row['creation_date'],"",2);
$label = $row['label'];
//echo "ZONE ID: " . $zone_id;

echo '<ROW MODID="96" RECORDID="3">
<COL><DATA>' . $artist . '</DATA></COL><COL><DATA>' . $title . '</DATA></COL><COL><DATA>' . $category_id . '</DATA></COL><COL><DATA>' . $review . '</DATA></COL><COL><DATA>' . $reviewer . '</DATA></COL><COL><DATA>' . $cancon. '</DATA></COL><COL><DATA>' . $date_added .'</DATA></COL><COL><DATA>' . $label .'</DATA></COL>';

echo '</ROW>';

}


echo '</RESULTSET></FMPXMLRESULT>';



} else {

echo "access denied.";
}




function dateformat($date, $end_date, $format = 1) { 

	preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/',$date,$date_parts);
	preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/',$end_date,$end_date_parts);
	$months = array ('1' => 'January' , 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); 		    //print_r ($months);
	$monthnum = ltrim ($date_parts[2], "0"); //echo "--------" . $monthnum;
	$day = ltrim ($date_parts[3], "0"); //echo "--------" . $monthnum;
	$month = $months[$monthnum];
	$end_monthnum = ltrim ($end_date_parts[2], "0"); //echo "--------" . $monthnum;
	$end_day = ltrim ($end_date_parts[3], "0"); //echo "--------" . $monthnum;
	$end_month = $months[$end_monthnum];
	
	if ($format == 1)
	{
		if ($end_date) 
			{
				if ($end_monthnum != $monthnum)
				{
				$date = $month . " $day-$end_month $end_day, $date_parts[1]";  /// Jan 23 - Feb 2, 2008
				} else {
				$date = $month . " $day-$end_day, $date_parts[1]"; /// Jan 23 - 25, 2008
				}
			} else {
				$date = $month . " $day, $date_parts[1]"; /// Jan 23, 2008
				
			}
	}
	
	if ($format == 2)
	{
		$date = $monthnum . "/$day/" . $date_parts[1]; /// 12/24/08
	}
	
	if ($format == 3)
	{
		$date = $monthnum . "/$day"; /// 12/24
	}
	
	return $date;
} 



?>

